package com.bilibili.delayed;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;
import java.util.Date;

public class Producer {
    public static void main(String[] args) throws Exception {
        //1.创建生产者对象
        DefaultMQProducer producer = new DefaultMQProducer("delayed_producer_group");

        //2.设置nameserver地址
        producer.setNamesrvAddr("localhost:9876");

        //3.启动
        producer.start();

        //4.创建消息,并指定Topic，Tag和消息体
        Message message = new Message("delayed","hi","键盘敲烂".getBytes(StandardCharsets.UTF_8));
        message.setDelayTimeLevel(3);
        SendResult send = producer.send(message);
        System.out.println(new Date());
        System.out.println(send);
        //5.终止
        producer.shutdown();

    }
}
